<div class="pageContent">
    <form method="post" action="${rc.getContextPath()}/manage/performance/savePerformance" class="pageForm required-validate" onsubmit="return validateCallback(this, hrPerformance._performancenAddAjaxDone)">
        <input type="hidden" name="navTabId" value="${navTabId!''}" />
        <div class="pageFormContent">
            <fieldset>
                <dl class="notnormal">
                    <dt><@label key='personnelCode.C,colon'>人员编号：</@label></dt>
                    <dd>
                        <input class="required look"  id="personnelLookup.personnelCode" name="personnelCode" type="text" postField="personnelCode" suggestFields="personnelCode,personnelName,workCenterCode,workCenterText" 
                        suggestUrl="${rc.getContextPath()}/manage/personnel/personnelSuggest" lookupGroup="personnelLookup"
                        warn="<@label key='personnelCode.C,doesNotExist.C'>人员编号不存存在</@label>" remote="${rc.getContextPath()}/manage/personnel/validatePersonnel" />
                        <a class="btnLook" href="${rc.getContextPath()}/manage/personnel/personnelLookUp?lookupType=radio" rel="personnel_dialog"   title="<@label key='select.C,personnelCode.C'>选择人员</@label>" lookupGroup="personnelLookup" ></a>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="personnelName.C,colon">姓名：</@label></dt>
                    <dd>
                        <input id="personnelLookup.personnelName"  name="personnelName" readonly="readonly" type="text"/>
                        <input name="workCenterCode" id="personnelLookup.workCenterCode" type="hidden" />
                    </dd>
                </dl>
                <!-- <dl>
                    <dt><@label key="personnelType.C,colon">人员类型：</@label></dt>
                    <dd>
                        <select name="personnelTypeCode" class="required"></select>
                    </dd>
                </dl> -->
                <dl class="notnormal">
                    <dt><@label key='date.C,colon'>日期：</@label></label></dt>
                    <dd>
                        <input type="text" class="required date"  name="theDate" readonly  /><a class="inputDateButton" href="javascript:;">选择</a>
                    </dd>
                </dl>
                <dl class="notnormal">
                    <dt><@label key='startTime.C,colon'>开始时间</@label></label></dt>
                    <dd>
                        <input type="text" class="required date"  max_Date="{endDatetime}" name="startDatetime" readonly dateFmt="yyyy-MM-dd HH:mm:ss" /><a class="inputDateButton" href="javascript:;">选择</a>
                    </dd>
                </dl>
                <dl class="notnormal">
                    <dt><@label key='endTime.C,colon'>结束时间</@label></dt>
                    <dd>
                        <input type="text" class="required date"  min_Date="{startDatetime}" name="endDatetime" readonly dateFmt="yyyy-MM-dd HH:mm:ss"/><a class="inputDateButton" href="javascript:;">选择</a>
                    </dd>
                </dl>
                <dl class="notnormal">
                    <dt><@label key='materialCode.C,colon'>物料编码：</@label></dt>
                    <dd>
                        <input class="required look" id="materialLookup.materialCode" name="materialCode" type="text" postField="materialCode" suggestFields="materialCode,materialText" 
                        suggestUrl="${rc.getContextPath()}/manage/material/componentSuggest" lookupGroup="materialLookup" remote="${rc.getContextPath()}/manage/material/validateMaterial" warn="<@label key='materialCodeNotExists.M'>物料编号不存在</@label>"/>
                        <a class="btnLook" href="${rc.getContextPath()}/manage/material/componentLookUp?lookupType=radio" rel="materialLookup_dialog" title="<@label key='select.C,materialCode.C'>选择物料</@label>" lookupGroup="materialLookup" ></a>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key='materialText.C,colon'>物料描述：</@label></dt>
                    <dd><input type="text" readonly id="materialLookup.materialText" name="materialText" /></dd>
                </dl>
                <dl>
                    <dt><@label key='quantity.C,colon'>数量</@label></dt>
                    <dd><input type="text" name="quantity" class="required number" min="1" maxlength="15"/></dd>
                </dl>
                <dl class="notnormal">
                    <dt><@label key="shiftingWorkCenter.C,colon">实际工作中心：</@label></dt>
                    <dd><input id="shiftingWorkCenter.workCenterText" class="required look" type="text" readonly="readonly" />
                     <a class="btnLook" href="${rc.getContextPath()}/manage/workCenter/workCenterLookup?hr=hr&lookupType=radio" rel="workCenterLookup_dialog" title="<@label key='select.C,shiftingWorkCenter.C'>选择实际工作中心</@label>" lookupGroup="shiftingWorkCenter" ></a>
                    <input type="hidden" name="shiftingWorkCenterCode" postField="workCenterCode" warn="<@label key='workCenterNotExitstOrLocked.M'>工作中心不存在或已被使用</@label>"  id="shiftingWorkCenter.workCenterCode" remote="${rc.getContextPath()}/manage/workCenter/validateWorkCenterForHr"/>
                    </dd>
                </dl>
                
                <dl>
                    <dt><@label key='description.C,colon'>备注</@label></dt>
                    <dd><input type="text" name="memo"  maxlength="200"/></dd>
                </dl>
                <dl>
                    <dd><span style="color:red" id="performanceMsgInfo"></span></dd>
                </dl>
            </fieldset>
        </div>
        <div class="formBar">
        <ul>
            <li><div class="buttonActive"><div class="buttonContent"><button type="submit"><@label key="save.B">保存</@label></button></div></div></li>
            <li>
                <div class="buttonActiveGrey"><div class="buttonContent"><button type="button" class="close"><@label key="close.B">关闭</@label></button></div></div>
            </li>
        </ul>
       </div>
    </form>
    <table id="performanceLog" class="table border" width="160%" layoutH="280" style="overflow:auto;">
        <thead>
            <tr>
                <th width="40"><@label key="serialNumber.C">序号</@label></th>
                <th width="100"><@label key='personnelCode.C'>人员编号</@label></th>
                <th width="100"><@label key='date.C'>日期</@label></th>
                <th width="100" ><@label key='personnelName.C'>姓名</@label></th>
                <th width="100"><@label key="workCenter.C">工作中心：</@label></th>
                <th width="120"><@label key="shiftingWorkCenter.C">实际工作中心</@label></th>
                <th width="140"><@label key='startTime.C'>开始时间</@label></th>
                <th width="140"><@label key='endTime.C'>结束时间</@label></th>
                <th width="100"><@label key='materialCode.C'>物料编号</@label></th>
                <th width="100"><@label key='materialText.C'>物料描述</@label></th>
                <th width="80"><@label key='quantity.C'>数量</@label></th>
                <th width="120"><@label key='description.C'>备注</@label></th>
            </tr>
        </thead>
        <tbody id='tbody'>
        </tbody>
    </table>
</div>
<script type="text/javascript">

    var hrPerformance = {
    	_saveCount : 0,
    	
    	_getNextTheDate : function(date){
    		if (date.getTime) {
                return new Date(date.getTime() + 24 * 60 * 60 * 1000);
            } else {
                return new Date(date.parseDate('yyyy-MM-dd HH:mm').getTime() + 24 * 60 * 60 * 1000);
            }
    	},
    	
    	_performancenAddAjaxDone : function(json){
    		DWZ.ajaxDone(json);
            if (json.statusCode == DWZ.statusCode.ok) {
                if (json.navTabId){
                    navTab.reload(json.forwardUrl, {navTabId: json.navTabId});
                } 
                hrPerformance._saveCount ++;
                var data = json.data;
                if(!data || !data.id)
                    return;
                var $tbody = $("#performanceLog .gridTbody", $.pdialog.getCurrent()).find("table tbody");
                var $tr = $("<tr/>");
                for(var i = 0; i < 12; i++) {
                     $tr.append('<td/>');
                }
                $("td:eq(0)", $tr).append(hrPerformance._saveCount);
                $("td:eq(1)", $tr).append(data.personnelCode);
                $("td:eq(2)", $tr).append(new Date(parseInt(data.theDate)).formatDate("yyyy-MM-dd"));
                $("td:eq(3)", $tr).append(data.personnelName);
                //$("td:eq(4)", $tr).append(data.personnelTypeCode);
                $("td:eq(4)", $tr).append(data.workCenterCode);
                $("td:eq(5)", $tr).append(data.shiftingWorkCenterCode);
                $("td:eq(6)", $tr).append(new Date(parseInt(data.startDatetime)).formatDate("yyyy-MM-dd HH:mm:ss"));
                $("td:eq(7)", $tr).append(new Date(parseInt(data.endDatetime)).formatDate("yyyy-MM-dd HH:mm:ss"));
                $("td:eq(8)", $tr).append(data.materialCode);
                $("td:eq(9)", $tr).append(data.materialText);
                $("td:eq(10)", $tr).append(data.quantity);
                $("td:eq(11)", $tr).append(data.memo);
                $tr.prependTo($tbody );
                $.jTableTool.initGridColumnWidth($tbody.parents('.grid:first'));
            }
    	},
    	_setPersonnelType : function() {
    		 var personnelCode =  $("input[name='personnelCode']", $.pdialog.getCurrent()).val();
    	        var $personnelType = $("select[name=personnelTypeCode]", $.pdialog.getCurrent())
    	        if(personnelCode && personnelCode!=""){
    	            $("span#performanceMsgInfo", $.pdialog.getCurrent()).html("");
    	            $.DWZajax({
    	                url: hostUrl+"/ptassign/getPTAsByPersonnel",
    	                data: {'personnelCode': personnelCode},
    	                callback:function(data){
    	                    if (data.length) {
    	                        $personnelType.empty();
    	                        $.each(data, function(index, pta){
    	                            $('<option/>').attr({
    	                                value: pta.personnelTypeCode,
    	                                selected: pta.defaultTypeFlag == 1
    	                            }).text(pta.typeText).appendTo($personnelType);
    	                        });
    	                    } else {
    	                        $personnelType.empty()[0].selectedIndex = -1;
    	                        $("span#performanceMsgInfo", $.pdialog.getCurrent()).html("<@label key='personnel_noPersonnelType.M'>此人员没有维护人员与类型，请从新选择</@label>");
    	                    }
    	                }
    	            })
    	        }
    	}
    }
    $(function(){
        var $timeInput = $('[name=startDatetime],[name=endDatetime]', $.pdialog.getCurrent());
        var $date = $('[name=theDate]', $.pdialog.getCurrent());
        var today = new Date().formatDate("yyyy-MM-dd");
        $date.on('change', function(){
            if (this.value) {
                $timeInput.attr('minDate', this.value);
                $timeInput.attr('maxDate', hrPerformance._getNextTheDate(this.value).formatDate('yyyy-MM-dd'));
                $timeInput.val("");
            } else {
                $timeInput.attr('minDate', today);
                $timeInput.attr('maxDate', hrPerformance._getNextTheDate(today).formatDate('yyyy-MM-dd'));
            }
        })
    })
</script>